//
//  JMTeamRankTController.m
//  jiMuOperate
//
//  Created by 胡梅方 on 16/5/10.
//  Copyright © 2016年 jinXinFengLi. All rights reserved.
//

#import "JMTeamRankTController.h"
#import "teamRankCell.h"
#import "teamRankModel.h"
#import "JMReleaseStrVController.h"
@interface JMTeamRankTController ()

#import "JMTaskTVController.h"

@interface teamRankTVController ()
@property(nonatomic,strong)NSMutableArray *teamRanks;
@property(nonatomic,strong)teamRankCell *teamRankCell;
@property(nonatomic,strong)teamRankModel *teamRank;
@end

@implementation JMTeamRankTController

- (void)viewDidLoad {
    [super viewDidLoad];
    
     [[self navigationController] setNavigationBarHidden:NO animated:YES];
    
    self.navigationItem.title = @"团队排名";
    HIDETABVLINE(self.tableView);
    [self cellAttribute];
    [self loadData];
}
-(void)cellAttribute{
    self.tableView.rowHeight = 60;
    self.tableView.rowHeight = [ToolViewAndData autoLayoutBackHeight: self.tableView.rowHeight];
}
-(NSMutableArray *)teamRanks{
    if (_teamRanks==nil) {
        [self loadData];
    }
    
    return _teamRanks;
}
-(void)loadData{
    /**
     *  api/Team/GetPineConeParkRankingsList?page={page}&pageSize={pageSize}
     */
    NSString *strurl = [NSString stringWithFormat:@"%@%@&pageSize=%@",JMGetPineConeParkRankingsList,@"1",@"5"];
    
    NSArray *arrayR = @[@"",strurl,@"GET"];
    [Request startRequestWithArray:arrayR FinishedBlock:^(NSData *data) {
        if (data) {
            //请求成功，解析json数据
            NSDictionary *dict = [JMData dictAndTestData:data];
            
            NSMutableArray *array =dict[@"data"];
            
            NSMutableArray *temparray = [NSMutableArray array];
            
            for (NSDictionary *dict in array) {
                
                //  字典转模型
                teamRankModel *teamRank = [teamRankModel teamRankWithDict:dict];
                [temparray addObject:teamRank];
                
            }
            _teamRanks = temparray;
            
            [self.tableView reloadData];
            
        }
    } FailBlock:^(NSString *string) {
        NSLog(@"加载失败－－－－－－－");
    }];
    //    回到主线程
    dispatch_async(dispatch_get_main_queue(), ^{
    });
    
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _teamRanks.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *tRankCell = @"stageCell";
    teamRankCell *cell = [tableView dequeueReusableCellWithIdentifier:tRankCell];
    
    if (cell == nil) {
        cell = [[teamRankCell alloc]init];
        _teamRankCell = cell;
        //    获取对应的行
        teamRankModel *teamR = _teamRanks[indexPath.row];
        cell.SortLabel.text = [NSString stringWithFormat:@"%ld",(long)teamR.Sort];
        cell.nameLabel.text =[NSString stringWithFormat:@"团队名称：%@",teamR.Name];
        
        cell.NumbeLabel.text = [NSString stringWithFormat:@"人数%ld人",(long)teamR.CommuneNumber];
        NSString *strsds = [NSString stringWithFormat:@"总收益:%ld松籽",(long)teamR.SumProfit ];
        NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:strsds];
        NSRange redRange = NSMakeRange(4, [noteStr length]-6);
        [noteStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:redRange];
        
        [cell.SumProfitLabel setAttributedText:noteStr];
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    JMTaskTVController *Vc = [[JMTaskTVController alloc] init];
    [self.navigationController pushViewController:Vc animated:YES];
}
@end
